#include <stdio.h>
#include <stdbool.h>
#define Max 100
#define ElementType int
//循环队列
typedef struct 
{
    ElementType arr[Max];
    int front;//对头下标
    int rear;//队尾下标
    int len;//长度
}Queue;

void InitQueue(Queue *q)
{
    for(int i = 0; i < Max; i++)
    {
        q->arr[i] = 0;
    }
    q->front = 0;
    q->rear = 0;
    q->len = 0;
}

//入队列
void Push(Queue *q,ElementType element)
{
    //浪费一块空间
    //if((q->rear + 1) % Max == q->front)
    if(q->len == Max)
    {
        printf("队列已满!\n");
        return;
    }

    q->arr[q->rear] = element;
    q->rear++;
    q->rear %= Max;
    q->len++;
}

//出队列
void Pop(Queue *q)
{
    //if(q->front == q->rear)
    if(q->len == 0)
    {
        printf("队列空!\n");
        return;
    }

    q->front++;
    q->front %= Max;
    q->len--;
}

ElementType* GetFront(Queue *q)
{
    if(q->front == q->rear)
    {
        return NULL;
    }
    return &q->arr[q->front];
}

bool IsQueueEmpty(Queue *q)
{
    return q->front == q->rear;
}

int main()
{
    Queue q;
    InitQueue(&q);

    for(int i = 0; i < 10; i++)
    {
        Push(&q,i+1);
    }
    printf("\n");
    while(IsQueueEmpty(&q) == false)
    {
        printf("%d ",*GetFront(&q));
        Pop(&q);
    }
    printf("\n");
    return 0;
}